/**
 * @file common.h
 * @author Quan.Shen (ctrlshift12138@gmail.com)
 * @brief 
 * @version 0.1
 * @date 2025-07-22
 * 
 * @copyright Copyright (c) 2025
 * 
 */

#ifndef __COMMON_H
#define __COMMON_H

#include "stm32f10x.h"
#include "board.h"

#define IS_AF(c)             ((c >= 'A') && (c <= 'F'))
#define IS_af(c)             ((c >= 'a') && (c <= 'f'))
#define IS_09(c)             ((c >= '0') && (c <= '9'))
#define ISVALIDHEX(c)        IS_AF(c) || IS_af(c) || IS_09(c)
#define ISVALIDDEC(c)        IS_09(c)
#define CONVERTDEC(c)        (c - '0')

#define CONVERTHEX_alpha(c)  (IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10))
#define CONVERTHEX(c)        (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c))

uint8_t SerialKeyPressed(uint8_t *key);
uint8_t GetKey(void);
void Int2Str(uint8_t *str, uint32_t uint_num);
uint32_t Str2Int(uint8_t *inputstr, uint32_t *intnum);
void SerialPutChar(uint8_t ch);

#endif /* __COMMON_H */
